# Maintainer: yumetodo <yume-wikijp@live.jp>

_realname=tl-expected
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.1.0
pkgrel=1
pkgdesc="C++11/14/17 std::expected with functional-style extensions (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/TartanLlama/expected'
license=('spdx:CC0-1.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/TartanLlama/expected/archive/v${pkgver}/expected-v${pkgver}.tar.gz")
sha256sums=('1db357f46dd2b24447156aaf970c4c40a793ef12a8a9c2ad9e096d9801368df6')

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_CXX_STANDARD=17 \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DEXPECTED_BUILD_TESTS=OFF \
    -DEXPECTED_BUILD_PACKAGE=OFF \
    ../expected-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build ./
}

check() {
  cd "build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/cmake -DEXPECTED_BUILD_TESTS=ON ../expected-${pkgver}
  ${MINGW_PREFIX}/bin/cmake --build .
  ./tests
}

package() {
  cd "build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  install -Dm644 "${srcdir}"/expected-${pkgver}/COPYING \
    "${pkgdir}${MINGW_PREFIX}/usr/share/licenses/${_realname}/LICENSE"
}
